
import Vuex from 'vuex'
import Vue from 'vue'
import * as types from './types'
import instance from "../http";

Vue.use(Vuex);
export default Vue.prototype.$store = new Vuex.Store({
    state: {
        token: null,
        expireTime:"",
        refreshTime:"",
        createTime:"",
        userName: '',
        auth:'',
        permissionList:'',
        refreshWebsocket:false,
    },
    mutations: {
        [types.LOGIN]: (state, data) => {
            localStorage.token = data.token;
            localStorage.createTime = data.createTime;
            localStorage.expireTime = data.expireTime;
            localStorage.refreshTime = data.refreshTime;
            state.token = data.token;
            state.createTime = data.createTime;
            state.expireTime = data.expireTime;
            state.refreshTime = data.refreshTime;
        },
        [types.LOGOUT]: (state) => {
            localStorage.removeItem('token');
            state.token = null
        },
        [types.USERNAME]: (state, data) => {
            localStorage.userName = data;
            state.userName = data;
        },
        [types.AUTH]: (state, data) => {
            localStorage.auth = data;
            state.auth = data;
        },
        [types.PERMISSION]: (state, data) => {
            localStorage.permissionList = data;
            state.permissionList = data;
        },
        [types.REFRESH_WEBSOCKET]: (state, data) => {
            state.refreshWebsocket = data;
        },
    }
})
